package com.zzty.txj.serviceImpl;

import com.alibaba.fastjson.JSONObject;
import com.zzty.txj.entity.Clazz;
import com.zzty.txj.entity.User;
import com.zzty.txj.service.ClazzService;
import org.apache.http.entity.StringEntity;
import com.zzty.txj.util.HttpUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

import static com.zzty.txj.util.HttpUtil.httpGet;
import static com.zzty.txj.util.HttpUtil.httpPostWithJSON;

@Service
public class ClazzServiceImpl implements ClazzService {
    @Value("${url.user.getClazz}")
    String url;
    @Override
    public List<Clazz> getClazz(){
        String us=null;
        try {
           us = httpGet(url);
           // us=httpGet("http://b0b38bf7.ngrok.io/us ercenter/clazz/getClazz");
        } catch (Exception e) {
            e.printStackTrace();
        }
        List<Clazz> clazzes=JSONObject.parseArray(us,Clazz.class);
        return clazzes;
    }

    @Value("${url1.user.getUserByClazzId}")
    String url1;
    @Override
    public List<User> getUsers(Clazz clazz) {
        String us=null;

        try {
          us=httpGet(url1+"/"+clazz.getId());
          // us = httpGet("http://bad4862f.ngrok.io/usercenter/user/getUserByClazzId/"+clazz.getId());
            System.out.println("us========"+us);
        } catch (Exception e) {
            e.printStackTrace();
        }
        List<User>users= JSONObject.parseArray(us,User.class);

        return users;
    }
}
